//
//  EmoticonAttachment.swift
//  EmoticonKeyBoard
//
//  Created by yang on 15/11/22.
//  Copyright © 2015年 yang. All rights reserved.
//

import UIKit

class EmoticonAttachment: NSTextAttachment {

    var chs:String?
    //将图片添加到附件中 -> 转换成属性文本
    func emoticonimageText(emoticon:Emoticon,font:UIFont) -> NSAttributedString{
        //在附件中添加图片
        image = UIImage(contentsOfFile: emoticon.imagePath ?? "")
        chs = emoticon.chs
        //设置附件的大小
        let height = font.lineHeight
        bounds = CGRect(x: 0, y: -4, width: height, height: height)
        //将附件转换为属性文本
        let imageText = NSMutableAttributedString(attributedString: NSAttributedString(attachment: self))
        //文本字体属性
        imageText.addAttribute(NSFontAttributeName, value: font, range: NSMakeRange(0, 1))
        return imageText
    }
}
